//
//  QZUserMsgViewController.m
//  WeiWeiHaircut
//
//  Created by 上官惠阳 on 15/12/10.
//  Copyright © 2015年 超群. All rights reserved.
//

#import "QZUserMsgViewController.h"
#import "PersonUpperCell.h"
#import "PersonMiddleCell.h"
#import "ModifyInfoViewController.h"


@interface QZUserMsgViewController ()

@end

@implementation QZUserMsgViewController
{
    NSArray *_headTitleArr;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.tableSource removeAllObjects];
    [self createData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self titleWithSting:@"个人资料"];
    [self addBtnOnNavWithTitle:@"我" andImageName:@"返回" andTarget:self andAction:@selector(backAction) andFrame:CGRectMake(0, 0, 45, 20) andDirection:left];
    
    [self createTableViewWithPlainStyle:YES andSeparatorStyleNone:YES andBackGroudImageName:nil];
    self.tableView.backgroundColor = BACKGROUDCOLOR;
    
    [self registCellWithNib:@"PersonUpperCell" addIdentifier:@"upCell" addHeight:0];
    [self registCellWithNib:@"PersonMiddleCell" addIdentifier:@"midCell" addHeight:0];
    
    [self createData];
}

- (void)createData
{
    [self.tableSource setArray:@[@"",[QZUserInfo sign],[QZUserInfo address],[NSString stringWithFormat:@"%@级",[QZUserInfo userHYdjId]]]];
    _headTitleArr = @[@"",@"签名",@"地区",@"会员等级"];
    [self.tableView reloadData];
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 100;
    }
    else if (indexPath.row == 1) {
        return 88;
    }
    else if (indexPath.row == 2 || indexPath.row == 3) {
        return 68;
    }else
        return 0;
}
#pragma mark - UITableViewDataSource
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        PersonUpperCell *upperCell = [tableView dequeueReusableCellWithIdentifier:@"upCell" forIndexPath:indexPath];
        upperCell.contentView.backgroundColor = BACKGROUDCOLOR;
        upperCell.shopNameLabel.textColor = FiveOneColor;
        upperCell.statusLabel.textColor = OneFiveThreeColor;
        upperCell.normalLab.textColor = OneFiveThreeColor;
        upperCell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        upperCell.shopNameLabel.text = [QZUserInfo nickName];
        upperCell.statusLabel.text = [QZUserInfo userType];
        upperCell.headImage.image = [QZUserInfo headImage];
        
        NSString *imageName;
        if ([[QZUserInfo sex] isEqualToString:@"男"]) {
            imageName = @"男";
        }else if ([[QZUserInfo sex] isEqualToString:@"女"]){
            imageName = @"女";
        }else{
            upperCell.sexImage.hidden = YES;
        }
        upperCell.sexImage.image = [UIImage imageNamed:imageName];
        return upperCell;
    }else {
        PersonMiddleCell *middleCell = [tableView dequeueReusableCellWithIdentifier:@"midCell" forIndexPath:indexPath];
        middleCell.contentView.backgroundColor = BACKGROUDCOLOR;
        middleCell.personSignTextView.textColor = FiveOneColor;
        middleCell.headTitleLabel.text = _headTitleArr[indexPath.row];
        middleCell.personSignTextView.text  = self.tableSource[indexPath.row];
        middleCell.personSignTextView.font = [UIFont systemFontOfSize:16];
        middleCell.selectionStyle = UITableViewCellSelectionStyleNone;
        //画一条线
        [middleCell.contentView setlineFrame:CGRectMake(0, middleCell.contentView.frame.size.height, WIDTH, .3f) lineColor:[UIColor lightGrayColor] lineAlpha:0.5];
        return middleCell;
    }
}
-(void)actionAtIndexPath:(NSIndexPath *)indexPath
{
    ModifyInfoViewController *infoVc = [[ModifyInfoViewController alloc]init];
    [self.navigationController pushViewController:infoVc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
